home *** CD-ROM | disk | FTP | other *** search
/ MPEG Toolkit / MPEG Toolkit.iso / os2 / mpegplay / video.h < prev    next >
C/C++ Source or Header  |  1997-01-01  |  12KB  |  295 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <stdio.h>
  22. #include <setjmp.h>
  23.  
  24. /* @@@ Fake up XWindows for OS/2 */
  25. #if defined(OS2)
  26. #include "xstub.h"
  27. #else
  28. #include <X11/Xlib.h>
  29. #include <X11/Xutil.h>
  30.  
  31. #ifdef SH_MEM
  32. #include <sys/ipc.h>
  33. #include <sys/shm.h>
  34. #include <X11/extensions/XShm.h>
  35. #endif
  36.  
  37. #endif
  38.  
  39. /* X11/xmd.h correctly defines INT32, etc */
  40. #ifndef XMD_H
  41. typedef int INT32;
  42. typedef short INT16;
  43. typedef char INT8;
  44. #endif
  45. typedef unsigned int UINT32;
  46. typedef unsigned short UINT16;
  47. typedef unsigned char UINT8;
  48.  
  49. /* Define Parsing error codes. */
  50.  
  51. #define SKIP_PICTURE -10
  52. #define SKIP_TO_START_CODE -1
  53. #define PARSE_OK 1
  54.  
  55. /* Define BOOLEAN, TRUE, and FALSE. */
  56.  
  57. #define BOOLEAN int
  58. #define TRUE 1
  59. #define FALSE 0
  60.  
  61. /* Set ring buffer size. */
  62.  
  63. #define RING_BUF_SIZE 5
  64.  
  65. /* Macros for picture code type. */
  66.  
  67. #define I_TYPE 1
  68. #define P_TYPE 2
  69. #define B_TYPE 3
  70.  
  71. /* Start codes. */
  72.  
  73. #define SEQ_END_CODE 0x000001b7
  74. #define SEQ_START_CODE 0x000001b3
  75. #define GOP_START_CODE 0x000001b8
  76. #define PICTURE_START_CODE 0x00000100
  77. #define SLICE_MIN_START_CODE 0x00000101
  78. #define SLICE_MAX_START_CODE 0x000001af
  79. #define EXT_START_CODE 0x000001b5
  80. #define USER_START_CODE 0x000001b2
  81.  
  82. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  83.  
  84. #define MB_QUANTUM 100
  85.  
  86. /* Macros used with macroblock address decoding. */
  87.  
  88. #define MB_STUFFING 34
  89. #define MB_ESCAPE 35
  90.  
  91. /* Lock flags for pict images. */
  92.  
  93. #define DISPLAY_LOCK 0x01
  94. #define PAST_LOCK 0x02
  95. #define FUTURE_LOCK 0x04
  96.  
  97. #define HYBRID_DITHER 0
  98. #define HYBRID2_DITHER 1
  99. #define FS4_DITHER 2
  100. #define FS2_DITHER 3
  101. #define FS2FAST_DITHER 4
  102. #define Twox2_DITHER 5
  103. #define GRAY_DITHER 6
  104. #define FULL_COLOR_DITHER 7
  105. #define NO_DITHER 8
  106. #define ORDERED_DITHER 9
  107. #define MONO_DITHER 10
  108. #define MONO_THRESHOLD 11
  109. #define ORDERED2_DITHER 12
  110. #define MBORDERED_DITHER 13
  111.  
  112. /* External declaration of row,col to zig zag conversion matrix. */
  113.  
  114. extern int scan[][8];
  115.  
  116. /* Temporary definition of time stamp structure. */
  117.  
  118. typedef int TimeStamp;
  119.  
  120. /* Structure with reconstructed pixel values. */
  121.  
  122. typedef struct pict_image {
  123.   unsigned char *luminance;              /* Luminance plane.   */
  124.   unsigned char *Cr;                     /* Cr plane.          */
  125.   unsigned char *Cb;                     /* Cb plane.          */
  126.   unsigned char *display;                /* Display plane.     */
  127.   int locked;                            /* Lock flag.         */
  128.   TimeStamp show_time;                   /* Presentation time. */
  129.  
  130. #ifdef SH_MEM
  131.   XShmSegmentInfo shminfo;               /* Segment info.  */
  132.   XImage *ximage;                        /* Ximage struct. */
  133. #endif
  134.  
  135. } PictImage;
  136.  
  137. /* Group of pictures structure. */
  138.  
  139. typedef struct GoP {
  140.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  141.   unsigned int tc_hours;                 /* Hour component of time code.   */
  142.   unsigned int tc_minutes;               /* Minute component of time code. */
  143.   unsigned int tc_seconds;               /* Second component of time code. */
  144.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  145.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  146.                         previous group of pictures.    */
  147.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  148.   char *ext_data;                        /* Extension data.                */
  149.   char *user_data;                       /* User data.                     */
  150. } GoP;
  151.  
  152. /* Picture structure. */
  153.  
  154. typedef struct pict {
  155.   unsigned int temp_ref;                 /* Temporal reference.             */
  156.   unsigned int code_type;                /* Frame type: P, B, I             */
  157.   unsigned int vbv_delay;                /* Buffer delay.                   */
  158.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  159.                         pixel values flag.              */
  160.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  161.   unsigned int forw_f;                   /* Used for vector decoding.       */
  162.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  163.                         pixel values flag.              */
  164.   unsigned int back_r_size;              /* Used in decoding.               */
  165.   unsigned int back_f;                   /* Used in decoding.               */
  166.   char *extra_info;                      /* Extra bit picture info.         */
  167.   char *ext_data;                        /* Extension data.                 */
  168.   char *user_data;                       /* User data.                      */
  169. } Pict;
  170.  
  171. /* Slice structure. */
  172.  
  173. typedef struct slice {
  174.   unsigned int vert_pos;                 /* Vertical position of slice. */
  175.   unsigned int quant_scale;              /* Quantization scale.         */
  176.   char *extra_info;                      /* Extra bit slice info.       */
  177. } Slice;
  178.  
  179. /* Macroblock structure. */
  180.  
  181. typedef struct macroblock {
  182.   int mb_address;                        /* Macroblock address.              */
  183.   int past_mb_addr;                      /* Previous mblock address.         */
  184.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  185.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  186.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  187.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  188.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  189.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  190.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  191.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  192.   unsigned int cbp;                      /* Coded block pattern.             */
  193.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  194.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  195.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  196.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  197.   int recon_right_for_prev;              /* Past right forw. vector.         */
  198.   int recon_down_for_prev;               /* Past down forw. vector.          */
  199.   int recon_right_back_prev;             /* Past right back vector.          */
  200.   int recon_down_back_prev;              /* Past down back vector.           */
  201. } Macroblock;
  202.  
  203. /* Block structure. */
  204.  
  205. typedef struct block {
  206.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  207.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  208.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  209.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  210. } Block;
  211.  
  212. /* Video stream structure. */
  213.  
  214. typedef struct vid_stream {
  215.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  216.   unsigned int v_size;                         /* Vert. size in pixels.      */
  217.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  218.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  219.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  220.   unsigned char picture_rate;                  /* Code for picture rate.     */
  221.   unsigned int bit_rate;                       /* Bit rate.                  */
  222.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  223.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  224.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  225.                           intracoded frames.         */
  226.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  227.                           non intracoded frames.     */
  228.   char *ext_data;                              /* Extension data.            */
  229.   char *user_data;                             /* User data.                 */
  230.   GoP group;                                   /* Current group of pict.     */
  231.   Pict picture;                                /* Current picture.           */
  232.   Slice slice;                                 /* Current slice.             */
  233.   Macroblock mblock;                           /* Current macroblock.        */
  234.   Block block;                                 /* Current block.             */
  235.   int state;                                   /* State of decoding.         */
  236.   int bit_offset;                              /* Bit offset in stream.      */
  237.   unsigned int *buffer;                        /* Pointer to next byte in
  238.                           buffer.                    */
  239.   int buf_length;                              /* Length of remaining buffer.*/
  240.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  241.   int max_buf_length;                          /* Max lenght of buffer.      */
  242.   PictImage *past;                             /* Past predictive frame.     */
  243.   PictImage *future;                           /* Future predictive frame.   */
  244.   PictImage *current;                          /* Current frame.             */
  245.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  246. } VidStream;   
  247.  
  248. /* Declaration of global pointer to current video stream. */
  249.  
  250. extern VidStream *curVidStream;
  251.  
  252. /* Declarataion of global display pointer. */
  253. extern Display *display;
  254.  
  255. /* Shared memory flag. */
  256. extern int shmemFlag;
  257.  
  258. /* Quiet mode flag. */
  259. extern int quietFlag;
  260.  
  261. /* Dither flags external declaration. */
  262. extern char *ditherFlags;
  263.  
  264. /* Definition of Contant integer scale factor. */
  265.  
  266. #define CONST_BITS 13
  267.  
  268. /* Misc DCT definitions */
  269. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  270. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  271.  
  272. #define GLOBAL            /* a function referenced thru EXTERNs */
  273.   
  274. typedef short DCTELEM;
  275. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  276.  
  277.  
  278. #ifdef SH_MEM
  279. extern int gXErrorFlag;
  280. #endif
  281.  
  282. extern double realTimeStart;
  283. extern int totNumFrames;
  284. extern int loopFlag;
  285. extern int noDisplayFlag;
  286. extern jmp_buf env;
  287.  
  288. #ifdef ANALYSIS
  289. extern unsigned int bitCount;
  290. extern int showEachFlag;
  291. extern unsigned int cacheHit[8][8];
  292. extern unsigned int cacheMiss[8][8];
  293. #endif
  294.  
  295.